{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7826cfe1-8577-4a7f-8aea-7fb7155dd866",
   "metadata": {},
   "source": [
    "## 下载包\n",
    "### pip install modelscope trl transformers ipywidgets addict vllm peft"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec33b321-40db-452b-bc3b-d96cf55a00f2",
   "metadata": {},
   "source": [
    "## 下载模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1deb912d-d84b-4f99-81ee-6160580c6c41",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Downloading Model to directory: ./models/Qwen/Qwen2.5-0.5B-Instruct\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "2025-03-03 00:28:44,249 - modelscope - INFO - Target directory already exists, skipping creation.\n"
     ]
    }
   ],
   "source": [
    "import os\n",
    "os.environ[\"HF_ENDPOINT\"] = \"https://hf-mirror.com\"\n",
    "from modelscope import snapshot_download\n",
    "from transformers import AutoTokenizer\n",
    "\n",
    "model_name = snapshot_download('Qwen/Qwen2.5-0.5B-Instruct',cache_dir='./models/')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "68682ead-a37c-4540-b24a-e7bc4a878fa6",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'./models/Qwen/Qwen2___5-0___5B-Instruct'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model_name"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fb6f7b4d-13c8-4708-8a3e-9694bf4ecff5",
   "metadata": {},
   "source": [
    "## 下载数据集"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "06881574-d741-4e1d-b584-2c7a1d65c4f2",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "from datasets import load_dataset\n",
    "\n",
    "ds = load_dataset(\"swulling/gsm8k_chinese\",cache_dir='./dataset/gsm8k-ch')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "5a80d43d-0dd2-4f89-94c0-491a6b49cb9b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DatasetDict({\n",
       "    test: Dataset({\n",
       "        features: ['question', 'answer', 'question_zh-cn', 'answer_only'],\n",
       "        num_rows: 1319\n",
       "    })\n",
       "    train: Dataset({\n",
       "        features: ['question', 'answer', 'question_zh-cn', 'answer_only'],\n",
       "        num_rows: 7473\n",
       "    })\n",
       "})"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ds"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eb2decb0-8cd3-4bd5-bfa6-0d50fdc76d18",
   "metadata": {},
   "source": [
    "## 定义推理模板和数据格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7d8709f6-f149-4c32-a9d3-6205d7aed3e9",
   "metadata": {},
   "outputs": [],
   "source": [
    "SYSTEM_PROMPT = \"\"\"\n",
    "按照如下格式生成：\n",
    "<think>\n",
    "...\n",
    "</think>\n",
    "<answer>\n",
    "...\n",
    "</answer>\n",
    "\"\"\"\n",
    "# def process_data(data):\n",
    "#     data = data.map(lambda x: {\n",
    "#         'prompt': [\n",
    "#             {'role': 'system', 'content': SYSTEM_PROMPT},\n",
    "#             {'role': 'user', 'content': x['question_zh-cn']}\n",
    "#         ],\n",
    "#         'answer': x['answer_only']\n",
    "#     }) \n",
    "#     return data\n",
    "\n",
    "\n",
    "# 如果你采用0.5b\n",
    "COT_FORMAT = \"\"\"\n",
    "<reasoning>\n",
    "{reasoning}\n",
    "</reasoning>\n",
    "<answer>\n",
    "{answer}\n",
    "</answer>\n",
    "\"\"\"\n",
    "def process_data(data):\n",
    "    data = data.map(lambda x: {\n",
    "        'prompt':[\n",
    "            {'role': 'system', 'content': SYSTEM_PROMPT},\n",
    "            # few shot\n",
    "            {'role': 'user', 'content': '数字2798654693里面有几个6?'},\n",
    "            {'role': 'assistant', 'content': COT_FORMAT.format(reasoning='可以将数字拆开看，2、7、9、8、6、5、4、6、9、3，我们可以数出有2个6',answer='2')},\n",
    "            {'role': 'user', 'content': x['question_zh-cn']}\n",
    "        ],\n",
    "        'answer': x['answer_only']\n",
    "    }) \n",
    "    return data\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c567712-d42a-45df-a380-8ed2dc0ba6b7",
   "metadata": {},
   "source": [
    "## 定义奖励函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9e78a0a4-bfa7-488a-8aed-a9be51f9c2ce",
   "metadata": {},
   "outputs": [],
   "source": [
    "import re\n",
    "def extract_answer(text):\n",
    "    answer = text.split(\"<answer>\")[-1]\n",
    "    answer = answer.split(\"</answer>\")[0]\n",
    "    return answer.strip()\n",
    "\n",
    "def mark_num(text):\n",
    "    reward = 0\n",
    "    if text.count(\"<think>\\n\") == 1:\n",
    "        reward += 0.125\n",
    "        \n",
    "    if text.count(\"</think>\\n\") == 1:\n",
    "        reward += 0.125\n",
    "        \n",
    "    if text.count(\"<answer>\\n\") == 1:\n",
    "        reward += 0.125\n",
    "        \n",
    "    if text.count(\"</answer>\\n\") == 1:\n",
    "        reward += 0.125\n",
    "    return reward\n",
    "\n",
    "# 生成答案是否正确的奖励\n",
    "def correctness_reward(prompts, completions, answer, **kwargs):\n",
    "    responses = [completion[0]['content'] for completion in completions]\n",
    "    extracted_responses = [extract_answer(r) for r in responses]\n",
    "    print(f\"问题:\\n{prompts[0][-1]['content']}\", f\"\\n答案:\\n{answer[0]}\", f\"\\n模型输出:\\n{responses[0]}\", f\"\\n提取后的答案:\\n{extracted_responses[0]}\")\n",
    "    return [2.0 if response == str(ans) else 0.0 for response, ans in zip(extracted_responses, answer)]\n",
    "# 生成答案是否是数字的奖励\n",
    "def digit_reward(completions, **kwargs):\n",
    "    responses = [completion[0]['content'] for completion in completions]\n",
    "    extracted_responses = [extract_answer(r) for r in responses]\n",
    "    return [0.5 if response.isdigit() else 0.0 for response in extracted_responses]\n",
    "\n",
    "# 格式奖励\n",
    "def hard_format_reward(completions, **kwargs):\n",
    "    pattern = r\"^<think>\\n.*?n</think>\\n<answer>\\n.*?\\n</answer>\\n$\"\n",
    "    responses = [completion[0][\"content\"] for completion in completions]\n",
    "    matches = [re.match(pattern, response) for response in responses]\n",
    "    return [1.5 if match else 0.0 for match in matches]\n",
    "# 格式奖励\n",
    "def soft_format_reward(completions, **kwargs):\n",
    "    pattern = r\"<think>.*?</think>\\s*<answer>.*?</answer>\"\n",
    "    responses = [completion[0][\"content\"] for completion in completions]\n",
    "    matches = [re.match(pattern, response) for response in responses]\n",
    "    return [1.0 if match else 0.0 for match in matches]\n",
    "# 标记奖励（改善格式奖励稀疏问题）\n",
    "def mark_reward(completions, **kwargs):\n",
    "    responses = [completion[0][\"content\"] for completion in completions]\n",
    "    return [mark_num(response) for response in responses]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fd3e491d-0a9e-49cb-8ca4-28fa33461ae5",
   "metadata": {},
   "source": [
    "## 模型下载和数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5a8b644c-a7e3-49d2-8eca-cf406142c081",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "PeftModelForCausalLM(\n",
       "  (base_model): LoraModel(\n",
       "    (model): Qwen2ForCausalLM(\n",
       "      (model): Qwen2Model(\n",
       "        (embed_tokens): Embedding(151936, 896)\n",
       "        (layers): ModuleList(\n",
       "          (0-23): 24 x Qwen2DecoderLayer(\n",
       "            (self_attn): Qwen2Attention(\n",
       "              (q_proj): lora.Linear(\n",
       "                (base_layer): Linear(in_features=896, out_features=896, bias=True)\n",
       "                (lora_dropout): ModuleDict(\n",
       "                  (default): Dropout(p=0.1, inplace=False)\n",
       "                )\n",
       "                (lora_A): ModuleDict(\n",
       "                  (default): Linear(in_features=896, out_features=8, bias=False)\n",
       "                )\n",
       "                (lora_B): ModuleDict(\n",
       "                  (default): Linear(in_features=8, out_features=896, bias=False)\n",
       "                )\n",
       "                (lora_embedding_A): ParameterDict()\n",
       "                (lora_embedding_B): ParameterDict()\n",
       "                (lora_magnitude_vector): ModuleDict()\n",
       "              )\n",
       "              (k_proj): lora.Linear(\n",
       "                (base_layer): Linear(in_features=896, out_features=128, bias=True)\n",
       "                (lora_dropout): ModuleDict(\n",
       "                  (default): Dropout(p=0.1, inplace=False)\n",
       "                )\n",
       "                (lora_A): ModuleDict(\n",
       "                  (default): Linear(in_features=896, out_features=8, bias=False)\n",
       "                )\n",
       "                (lora_B): ModuleDict(\n",
       "                  (default): Linear(in_features=8, out_features=128, bias=False)\n",
       "                )\n",
       "                (lora_embedding_A): ParameterDict()\n",
       "                (lora_embedding_B): ParameterDict()\n",
       "                (lora_magnitude_vector): ModuleDict()\n",
       "              )\n",
       "              (v_proj): lora.Linear(\n",
       "                (base_layer): Linear(in_features=896, out_features=128, bias=True)\n",
       "                (lora_dropout): ModuleDict(\n",
       "                  (default): Dropout(p=0.1, inplace=False)\n",
       "                )\n",
       "                (lora_A): ModuleDict(\n",
       "                  (default): Linear(in_features=896, out_features=8, bias=False)\n",
       "                )\n",
       "                (lora_B): ModuleDict(\n",
       "                  (default): Linear(in_features=8, out_features=128, bias=False)\n",
       "                )\n",
       "                (lora_embedding_A): ParameterDict()\n",
       "                (lora_embedding_B): ParameterDict()\n",
       "                (lora_magnitude_vector): ModuleDict()\n",
       "              )\n",
       "              (o_proj): lora.Linear(\n",
       "                (base_layer): Linear(in_features=896, out_features=896, bias=False)\n",
       "                (lora_dropout): ModuleDict(\n",
       "                  (default): Dropout(p=0.1, inplace=False)\n",
       "                )\n",
       "                (lora_A): ModuleDict(\n",
       "                  (default): Linear(in_features=896, out_features=8, bias=False)\n",
       "                )\n",
       "                (lora_B): ModuleDict(\n",
       "                  (default): Linear(in_features=8, out_features=896, bias=False)\n",
       "                )\n",
       "                (lora_embedding_A): ParameterDict()\n",
       "                (lora_embedding_B): ParameterDict()\n",
       "                (lora_magnitude_vector): ModuleDict()\n",
       "              )\n",
       "            )\n",
       "            (mlp): Qwen2MLP(\n",
       "              (gate_proj): lora.Linear(\n",
       "                (base_layer): Linear(in_features=896, out_features=4864, bias=False)\n",
       "                (lora_dropout): ModuleDict(\n",
       "                  (default): Dropout(p=0.1, inplace=False)\n",
       "                )\n",
       "                (lora_A): ModuleDict(\n",
       "                  (default): Linear(in_features=896, out_features=8, bias=False)\n",
       "                )\n",
       "                (lora_B): ModuleDict(\n",
       "                  (default): Linear(in_features=8, out_features=4864, bias=False)\n",
       "                )\n",
       "                (lora_embedding_A): ParameterDict()\n",
       "                (lora_embedding_B): ParameterDict()\n",
       "                (lora_magnitude_vector): ModuleDict()\n",
       "              )\n",
       "              (up_proj): lora.Linear(\n",
       "                (base_layer): Linear(in_features=896, out_features=4864, bias=False)\n",
       "                (lora_dropout): ModuleDict(\n",
       "                  (default): Dropout(p=0.1, inplace=False)\n",
       "                )\n",
       "                (lora_A): ModuleDict(\n",
       "                  (default): Linear(in_features=896, out_features=8, bias=False)\n",
       "                )\n",
       "                (lora_B): ModuleDict(\n",
       "                  (default): Linear(in_features=8, out_features=4864, bias=False)\n",
       "                )\n",
       "                (lora_embedding_A): ParameterDict()\n",
       "                (lora_embedding_B): ParameterDict()\n",
       "                (lora_magnitude_vector): ModuleDict()\n",
       "              )\n",
       "              (down_proj): lora.Linear(\n",
       "                (base_layer): Linear(in_features=4864, out_features=896, bias=False)\n",
       "                (lora_dropout): ModuleDict(\n",
       "                  (default): Dropout(p=0.1, inplace=False)\n",
       "                )\n",
       "                (lora_A): ModuleDict(\n",
       "                  (default): Linear(in_features=4864, out_features=8, bias=False)\n",
       "                )\n",
       "                (lora_B): ModuleDict(\n",
       "                  (default): Linear(in_features=8, out_features=896, bias=False)\n",
       "                )\n",
       "                (lora_embedding_A): ParameterDict()\n",
       "                (lora_embedding_B): ParameterDict()\n",
       "                (lora_magnitude_vector): ModuleDict()\n",
       "              )\n",
       "              (act_fn): SiLU()\n",
       "            )\n",
       "            (input_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n",
       "            (post_attention_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n",
       "          )\n",
       "        )\n",
       "        (norm): Qwen2RMSNorm((896,), eps=1e-06)\n",
       "        (rotary_emb): Qwen2RotaryEmbedding()\n",
       "      )\n",
       "      (lm_head): Linear(in_features=896, out_features=151936, bias=False)\n",
       "    )\n",
       "  )\n",
       ")"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from transformers import AutoTokenizer, AutoModelForCausalLM\n",
    "import trl\n",
    "from trl import GRPOConfig, GRPOTrainer\n",
    "from peft import LoraConfig, get_peft_model, TaskType\n",
    "# model_name = './models/Qwen/Qwen/Qwen2.5-7B-Instruct'\n",
    "model = AutoModelForCausalLM.from_pretrained(model_name)\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
    "tokenizer.pad_token=tokenizer.eos_token\n",
    "# 如果使用lora方法训练，取消如下注释\n",
    "lora_config = LoraConfig(\n",
    "r=8,  \n",
    "lora_alpha=256,  \n",
    "target_modules=[\"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\", \"gate_proj\", \"up_proj\", \"down_proj\"],\n",
    "lora_dropout=0.1, \n",
    "task_type=TaskType.CAUSAL_LM)\n",
    "# 使用lora方法训练\n",
    "model = get_peft_model(model, lora_config)\n",
    "model.cuda()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "c3f6c3ce-2150-4430-815c-032a5f4b7d7d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import torch\n",
    "indices = range(1000) # 取标号为第0个到第1000个数据\n",
    "sub_ds = ds[\"train\"].select(indices)\n",
    "data = process_data(sub_ds)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b769601a-bef2-4daf-95c0-f1336729bc6d",
   "metadata": {},
   "source": [
    "## 配置训练参数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "415cb2e0-8d47-4688-b24d-8e601c10bfa7",
   "metadata": {},
   "outputs": [],
   "source": [
    "output_dir=\"output_0.5b\"\n",
    "\n",
    "training_args = GRPOConfig(\n",
    "    output_dir=output_dir,\n",
    "    learning_rate=5e-6,\n",
    "    adam_beta1 = 0.9,\n",
    "    adam_beta2 = 0.99,\n",
    "    weight_decay = 0.1,\n",
    "    warmup_ratio = 0.1,\n",
    "    lr_scheduler_type='cosine',\n",
    "    logging_steps=1,\n",
    "    bf16=True,\n",
    "    per_device_train_batch_size=2,\n",
    "    gradient_accumulation_steps=4,\n",
    "    num_generations =2,\n",
    "    max_prompt_length=256,\n",
    "    max_completion_length=200,\n",
    "    num_train_epochs=1,\n",
    "    save_steps=100,\n",
    "    max_grad_norm=0.1,\n",
    "    log_on_each_node=False,\n",
    "    use_vllm=False,\n",
    "    report_to=\"tensorboard\",\n",
    "\n",
    ")\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "375c8c72-ec95-4280-af47-0c55cdb7ebf0",
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "No label_names provided for model class `PeftModelForCausalLM`. Since `PeftModel` hides base models input arguments, if label_names is not given, label_names can't be set automatically within `Trainer`. Note that empty label_names list will be used instead.\n"
     ]
    }
   ],
   "source": [
    "trainer = GRPOTrainer(\n",
    "model=model,\n",
    "processing_class=tokenizer,\n",
    "reward_funcs=[\n",
    "    mark_reward,\n",
    "    soft_format_reward,\n",
    "    hard_format_reward,\n",
    "    digit_reward,\n",
    "    correctness_reward\n",
    "    ],\n",
    "args=training_args,\n",
    "train_dataset=data,\n",
    "    \n",
    "\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "4d8a7055-d5d7-4778-88ab-33f7faaefcb1",
   "metadata": {},
   "source": [
    "## 训练"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ba3192a0-4493-4c87-ad15-997d99aeb379",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "问题:\n",
      "萨拉每天烤 10 个蛋糕，然后把它们放在冰箱里。他这样做了 5 天。然后卡罗尔过来吃了他的 12 个蛋糕。如果需要 2 罐糖霜来给一个蛋糕上糖霜，那么鲍勃需要多少罐糖霜来给剩下的蛋糕上糖霜？ \n",
      "答案:\n",
      "76 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "萨拉每天烤一盒蛋糕，所以如果她烤了5天，萨拉总共烤了10盘蛋糕。\n",
      "卡罗尔吃了萨拉烤的12个蛋糕，所以卡罗尔吃了12个蛋糕。\n",
      "萨拉烤的蛋糕总数减去卡罗尔烤的蛋糕数等于剩下未烤的蛋糕数。\n",
      "10盘蛋糕减去12盘蛋糕等于剩下未烤的蛋糕数。\n",
      "2罐糖霜可以给一个未烤的蛋糕上糖霜，所以我们需要计算12个蛋糕上糖霜所需的罐数。\n",
      "因此，12盘蛋糕需要2罐糖霜（12个蛋糕除以2罐糖霜）。\n",
      "12 - 12盘蛋糕需要2罐糖霜。\n",
      "12盘蛋糕需要2罐糖霜。\n",
      "所以，鲍勃需要2罐糖霜来给剩下的蛋糕上糖霜。\n",
      "</reasoning>\n",
      "<answer>\n",
      "2\n",
      "</answer> \n",
      "提取后的答案:\n",
      "2\n",
      "问题:\n",
      "杰克所在地区 40% 的蚊子感染了疟疾。 20%的蚊子感染了寨卡病毒。如果没有疫苗，被受感染的蚊子叮咬后感染这两种病毒的几率均为 50%。杰克正在服用一种实验性疟疾疫苗，可以将被叮咬后感染的几率降低 50%。如果杰克随机被蚊子叮咬，他感染寨卡病毒或疟疾的几率是多少？ \n",
      "答案:\n",
      "15 \n",
      "模型输出:\n",
      "首先，不需要考虑到寨卡病毒。被叮咬后感染寨卡病毒的几率为寨卡病毒感染的概率乘以被叮咬的概率，即\\(0.2 \\times 0.5 = 0.1\\)。被叮咬后感染疟疾的几率是受到感染的蚊子感染疟疾的几率乘以感染的蚊子感染的概率，即\\((0.8 \\times 0.5) = 0.4\\)。将这两个几率相加，得到感染者感染这两种疾病的几率为\\(0.1 + 0.4 = 0.5\\)。因此，如果杰克正在服用实验性疟疾疫苗，他感染寨卡病毒或疟疾的概率是50%。 \n",
      "提取后的答案:\n",
      "首先，不需要考虑到寨卡病毒。被叮咬后感染寨卡病毒的几率为寨卡病毒感染的概率乘以被叮咬的概率，即\\(0.2 \\times 0.5 = 0.1\\)。被叮咬后感染疟疾的几率是受到感染的蚊子感染疟疾的几率乘以感染的蚊子感染的概率，即\\((0.8 \\times 0.5) = 0.4\\)。将这两个几率相加，得到感染者感染这两种疾病的几率为\\(0.1 + 0.4 = 0.5\\)。因此，如果杰克正在服用实验性疟疾疫苗，他感染寨卡病毒或疟疾的概率是50%。\n",
      "问题:\n",
      "马特需要为他的家购买新盘子。他只想每周洗一次碗。每周三天只有他和他的儿子吃饭，他们每人用一盘。剩下的日子里，他的父母会和他们一起，那天每个人都用两个盘子。他需要购买多少个盘子？ \n",
      "答案:\n",
      "38 \n",
      "模型输出:\n",
      "马特每周洗碗4天，他的儿子每天用一个盘子，所以他们的总用盘子数为 \\(4 \\times 1 = 4\\) 个。剩下的3天，他的父母会使用2盘子，所以他们的总用盘子数为 \\(3 \\times 2 = 6\\) 个。\n",
      "\n",
      "所以，他需要购买的盘子总数为 \\(4 + 6 = 10\\) 个。 \n",
      "提取后的答案:\n",
      "马特每周洗碗4天，他的儿子每天用一个盘子，所以他们的总用盘子数为 \\(4 \\times 1 = 4\\) 个。剩下的3天，他的父母会使用2盘子，所以他们的总用盘子数为 \\(3 \\times 2 = 6\\) 个。\n",
      "\n",
      "所以，他需要购买的盘子总数为 \\(4 + 6 = 10\\) 个。\n",
      "问题:\n",
      "艾莎和阿玛莉拥有的金币比例是 10:45。如果他们拥有的硬币总数是 440，而 Amalie 将她拥有的 3/4 花在玩具上，她会剩下多少？ \n",
      "答案:\n",
      "90 \n",
      "模型输出:\n",
      "首先，我们需要计算艾莎拥有的金币总量。已知艾莎和阿玛莉的比例是 10:45，这意味着每 45 张硬币是 10 博尔。我们可以将阿玛莉的硬币总数除以比例的总和来找到阿玛莉的总硬币数量，再乘以比例的基数。艾莎的金币数量是阿玛莉的 3/4，因此我们可以得到总金币数量。\n",
      "\n",
      "为了简化计算，我们可以将艾莎和阿玛莉的金币比例转换为相同的分母，使得计算过程更为直观。\n",
      "\n",
      "因为 10:45 可以简化为 2:9，现在我们可以用 2 和 9 之间的最大比例关系进行计算来简化问题，即艾莎和阿玛莉金币比例是 2:9。所以，艾莎的金币数量是 2/11（因为艾莎和阿玛莉总数 \n",
      "提取后的答案:\n",
      "首先，我们需要计算艾莎拥有的金币总量。已知艾莎和阿玛莉的比例是 10:45，这意味着每 45 张硬币是 10 博尔。我们可以将阿玛莉的硬币总数除以比例的总和来找到阿玛莉的总硬币数量，再乘以比例的基数。艾莎的金币数量是阿玛莉的 3/4，因此我们可以得到总金币数量。\n",
      "\n",
      "为了简化计算，我们可以将艾莎和阿玛莉的金币比例转换为相同的分母，使得计算过程更为直观。\n",
      "\n",
      "因为 10:45 可以简化为 2:9，现在我们可以用 2 和 9 之间的最大比例关系进行计算来简化问题，即艾莎和阿玛莉金币比例是 2:9。所以，艾莎的金币数量是 2/11（因为艾莎和阿玛莉总数\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\n",
       "    <div>\n",
       "      \n",
       "      <progress value='10' max='250' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
       "      [ 10/250 02:31 < 1:15:40, 0.05 it/s, Epoch 0.04/1]\n",
       "    </div>\n",
       "    <table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       " <tr style=\"text-align: left;\">\n",
       "      <th>Step</th>\n",
       "      <th>Training Loss</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <td>1</td>\n",
       "      <td>-0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>2</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>3</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>4</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>5</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>6</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>7</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <td>8</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table><p>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "问题:\n",
      "约翰每天写 20 页。他写三本每本 400 页的书需要多长时间？ \n",
      "答案:\n",
      "60 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "1. 首先计算总共需要写的页数：20页/天 × 3本 × 400页/本 = 24000页\n",
      "2. 然后计算所需的总时间为：总页数 / 每天平均写的页数 = 24000页 / 20页/天\n",
      "3. 计算结果：24000页 / 20页/天 = 1200天\n",
      "4. 因此，约翰需要1200天完成两本不同的书的写作。\n",
      "</reasoning>\n",
      "<answer>\n",
      "1200天\n",
      "</answer>\n",
      " \n",
      "提取后的答案:\n",
      "1200天\n",
      "问题:\n",
      "一个教会有120名成员。 40%是成年人。其余的都是孩子。儿童比成人多多少个？ \n",
      "答案:\n",
      "24 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "120 * 40% = 48\n",
      "总人数：120 - 48 = 72\n",
      "儿童人数：72 - 48 = 24\n",
      "比成人比儿童多的儿童人数：24 - 48 = -24\n",
      "表示为负数，是因为是在计算负数\n",
      "</reasoning>\n",
      "<answer>\n",
      "-24\n",
      "</answer> \n",
      "提取后的答案:\n",
      "-24\n",
      "问题:\n",
      "杰瑞的两个女儿在不同的球队打垒球。他们本赛季各打8场比赛。每队每场比赛都会练习 4 个小时。如果每场比赛持续 2 小时，杰瑞总共会在球场上看女儿们打球和练习几个小时？ \n",
      "答案:\n",
      "96 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "总共有8场比赛，每队每场比赛练习4小时，所以每团队每周的练习时间是8 x 4 = 32小时。\n",
      "如果每场比赛持续2小时，那么每个团队每周的练习时间将是32/2 = 16小时。\n",
      "\n",
      "杰瑞是球队中的一名成员，这意味着他在所有比赛中都会看到女儿们打球和练习。所以杰瑞总共会在球场上看女儿们打球和练习16小时 x 2人 = 32小时\n",
      "\n",
      "综上所述，杰瑞总共会在球场上看女儿们打球和练习32小时。 \n",
      "提取后的答案:\n",
      "<reasoning>\n",
      "总共有8场比赛，每队每场比赛练习4小时，所以每团队每周的练习时间是8 x 4 = 32小时。\n",
      "如果每场比赛持续2小时，那么每个团队每周的练习时间将是32/2 = 16小时。\n",
      "\n",
      "杰瑞是球队中的一名成员，这意味着他在所有比赛中都会看到女儿们打球和练习。所以杰瑞总共会在球场上看女儿们打球和练习16小时 x 2人 = 32小时\n",
      "\n",
      "综上所述，杰瑞总共会在球场上看女儿们打球和练习32小时。\n",
      "问题:\n",
      "Maddy 的四年级班级需要制作 1000 张情人节贺卡才能举办披萨派对。班里有30个孩子。如果每个人都制作 8 张卡片，他们还需要制作多少张卡片才能举办披萨派对？ \n",
      "答案:\n",
      "760 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "30个孩子每人制作8张卡片，总共需要 \\(30 \\times 8 = 240\\) 张卡片\n",
      "如果总共需要制作1000张卡片，那么还需要制作 \\(1000 - 240 = 760\\) 张卡片\n",
      "</reasoning>\n",
      "<answer>\n",
      "760\n",
      "</answer> \n",
      "提取后的答案:\n",
      "760\n",
      "问题:\n",
      "保罗一边看电影，一边在跑步机上跑步。他可以在 12 分钟内跑完一英里。他看了两部电影，平均时长为1.5小时。他跑了多少英里？ \n",
      "答案:\n",
      "15 \n",
      "模型输出:\n",
      "首先，我们需要计算两部电影各自平均跑了多少分钟，然后将这两者相加。\n",
      "\n",
      "每部电影平均跑了1.5小时，由于1小时有60分钟，所以每部电影跑了1.5 × 60 = 90分钟。\n",
      "\n",
      "两部电影总共跑了90分钟 × 2 = 180分钟。\n",
      "\n",
      "接下来，我们需要将180分钟转换为英里。1英里等于60分钟，所以180分钟有180 / 60 = 3英里。\n",
      "\n",
      "因此，保罗跑的英里数是3。 \n",
      "提取后的答案:\n",
      "首先，我们需要计算两部电影各自平均跑了多少分钟，然后将这两者相加。\n",
      "\n",
      "每部电影平均跑了1.5小时，由于1小时有60分钟，所以每部电影跑了1.5 × 60 = 90分钟。\n",
      "\n",
      "两部电影总共跑了90分钟 × 2 = 180分钟。\n",
      "\n",
      "接下来，我们需要将180分钟转换为英里。1英里等于60分钟，所以180分钟有180 / 60 = 3英里。\n",
      "\n",
      "因此，保罗跑的英里数是3。\n",
      "问题:\n",
      "马内克斯是一名旅游巴士司机。他必须开车 55 英里到达目的地，然后再以 10 英里以外的另一条路返回起点。如果他能在 2 分钟内行驶 1 英里并在目的地停留 2 小时，那么巴士司机需要多长时间才能完成整个行程（以小时为单位）？ \n",
      "答案:\n",
      "6 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "首先，我们要计算马内克斯从起点到目的地总共需要行驶的小时数。车的行驶速度是 10 英里/小时，所以车从出发到返回到起点总共需要行驶 \\(55 \\text{ 英里} \\div 10 \\text{ 英里/小时} = 5.5 \\text{ 小时}\\)。\n",
      "\n",
      "然后我们计算马内克斯需要在途中停留的时间，这里是 2 小时。最后，我们需要计算总时长，并确保它不小于 2 小时。总时长是 5.5 小时，包括在途停留 2 小时和返回时间，所以总时间是 \\(5.5 + 2 = 7.5\\) 小时。\n",
      "\n",
      "所以，完成后总共的时长是 7.5 小时。\n",
      "</reasoning>\n",
      "<answer>\n",
      "7.5\n",
      "\n",
      "马内克斯完成整个 \n",
      "提取后的答案:\n",
      "7.5\n",
      "\n",
      "马内克斯完成整个\n",
      "问题:\n",
      "玛丽有 26 件蓝色衬衫和 36 件棕色衬衫。如果她捐出一半的蓝色衬衫和三分之一的棕色衬衫，她还剩下多少件衬衫？ \n",
      "答案:\n",
      "37 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "26/2 = 13 件蓝色衬衫\n",
      "36/3 = 12 件棕色衬衫\n",
      "26 - 13 = 13 件蓝色衬衫还有\n",
      "36 - 12 = 24 件棕色衬衫还有\n",
      "13 + 24 = 37 件衬衫\n",
      "</reasoning>\n",
      "<answer>\n",
      "37\n",
      "</answer> \n",
      "提取后的答案:\n",
      "37\n",
      "问题:\n",
      "珍妮想坐摩天轮、过山车、碰碰车。摩天轮5张票，过山车4张票，碰碰车4张票。 Jeanne 有 5 张票。珍妮还应该买多少张票？ \n",
      "答案:\n",
      "8 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "珍妮有5张票，她想买3种不同的票（摩天轮、过山车和碰碰车），所以她总共需要5张票÷3种票=1张票+1张票=2张票。\n",
      "</reasoning>\n",
      "<answer>\n",
      "她还应该买2张票\n",
      "</answer> \n",
      "提取后的答案:\n",
      "她还应该买2张票\n",
      "问题:\n",
      "克里斯蒂娜有3条蛇。 1 条蛇有 2 英尺长。另一条蛇长 16 英寸。最后一条蛇有 10 英寸长。她所有的蛇加起来有多少英寸？ \n",
      "答案:\n",
      "50 \n",
      "模型输出:\n",
      "首先，将其他三条蛇的长度统一：1 条是2 英尺，另一条是16 英寸，最后一条是10 英寸。 \n",
      "1 英尺等于12 英寸，所以：\n",
      "- 1 条蛇：2 英尺，即 2 × 12 = 24 英寸\n",
      "- 第二条蛇：16 英寸\n",
      "- 最后一条蛇：10 英寸\n",
      "\n",
      "接下来，我们将这些长度加在一起：\n",
      "24 英寸 + 16 英寸 + 10 英寸 = 50 英寸。\n",
      "\n",
      "所以，克里斯蒂娜所有的蛇加起来有 50 英寸。 \n",
      "提取后的答案:\n",
      "首先，将其他三条蛇的长度统一：1 条是2 英尺，另一条是16 英寸，最后一条是10 英寸。 \n",
      "1 英尺等于12 英寸，所以：\n",
      "- 1 条蛇：2 英尺，即 2 × 12 = 24 英寸\n",
      "- 第二条蛇：16 英寸\n",
      "- 最后一条蛇：10 英寸\n",
      "\n",
      "接下来，我们将这些长度加在一起：\n",
      "24 英寸 + 16 英寸 + 10 英寸 = 50 英寸。\n",
      "\n",
      "所以，克里斯蒂娜所有的蛇加起来有 50 英寸。\n",
      "问题:\n",
      "一个碗里有 30 种不同的坚果。如果吃掉 5/6 的坚果，还剩下多少坚果？ \n",
      "答案:\n",
      "5 \n",
      "模型输出:\n",
      "<thought>\n",
      "我们需要首先计算吃掉 5/6 的坚果之后还剩多少坚果。\n",
      "<answer>\n",
      "我们先用总共有多少种坚果除以吃掉的坚果比例，然后减去剩下的坚果。\n",
      "</answer>\n",
      "<code>\n",
      "let remaining = 30 - (5/6) * 30;\n",
      "console.log(remaining);\n",
      "</code>\n",
      "<thought>\n",
      "现在我们用计算结果来验证答案。\n",
      "<answer>\n",
      "5\n",
      "</answer> \n",
      "提取后的答案:\n",
      "5\n",
      "问题:\n",
      "卡拉需要开车去办很多事。她需要开车 8 英里去杂货店，6 英里去学校接孩子，12 英里去送孩子去参加足球训练，还需要从学校到足球训练的两倍距离才能让每个人都回家。如果 Carla 的汽车每加仑可行驶 25 英里，而汽油价格为 2.50 美元，那么 Carla 在这次旅行中需要花多少钱？ \n",
      "答案:\n",
      "5 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "她开车去杂货店需要8英里，去学校接孩子需要6英里，送孩子去参加足球训练需要12英里，这三段距离加起来需要34英里。从学校到足球训练需要这三段距离的一半，即还有一9.5英里。总共72英里，每加仑可行驶25英里，所以她需要购买72英里除以25英里/加仑，即3.08加仑的汽油。汽油的价格是2.50美元每加仑，所以她需要支付3.08加仑乘以2.50美元/加仑，即7.7美元。\n",
      "</reasoning>\n",
      "<answer>\n",
      "7.7美元\n",
      "</answer> \n",
      "提取后的答案:\n",
      "7.7美元\n",
      "问题:\n",
      "弗兰克每天烤两盘饼干，持续六天。弗兰克每天吃一块饼干，以确保它们味道好。泰德第六天过来吃了 4 块饼干。如果每个托盘制作 12 块饼干，那么泰德离开时还剩下多少块饼干？ \n",
      "答案:\n",
      "134 \n",
      "模型输出:\n",
      "首先，根据问题描述，每天烤两盘饼干，这意味着6天内共烤了6 * 2 = 12盘。因为弗兰克每天吃掉一块饼干，所以六天后实际上他们一共吃的饼干是12 - 1 = 11块。\n",
      "\n",
      "泰德第六天吃了4块，所以总共吃了11 + 4 = 15块饼干。然而，每个托盘制作12块饼干，我们可以将总共吃掉的饼干数量除以托盘数量得到泰德在最后离开时还能剩下多少饼干：\n",
      "\n",
      "15 ÷ 12 = 1余3\n",
      "\n",
      "这意味着泰德在离开时还会剩下3块饼干，因为有足够的饼干来应对剩余的食用人数。所以泰德离开时还剩下3块饼干。 \n",
      "提取后的答案:\n",
      "首先，根据问题描述，每天烤两盘饼干，这意味着6天内共烤了6 * 2 = 12盘。因为弗兰克每天吃掉一块饼干，所以六天后实际上他们一共吃的饼干是12 - 1 = 11块。\n",
      "\n",
      "泰德第六天吃了4块，所以总共吃了11 + 4 = 15块饼干。然而，每个托盘制作12块饼干，我们可以将总共吃掉的饼干数量除以托盘数量得到泰德在最后离开时还能剩下多少饼干：\n",
      "\n",
      "15 ÷ 12 = 1余3\n",
      "\n",
      "这意味着泰德在离开时还会剩下3块饼干，因为有足够的饼干来应对剩余的食用人数。所以泰德离开时还剩下3块饼干。\n",
      "问题:\n",
      "一座城堡里的粮食足够300人吃90天。 30天后，100人离开城堡。距离所有食物耗尽还有多少天？ \n",
      "答案:\n",
      "90 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "300人吃90天= 2700人\n",
      "30天= 90人\n",
      "总共有2700人 - 90人 = 2610人\n",
      "以后100人走了，所以剩下的人数为2610人 - 100人 = 2510人\n",
      "90天后，有2510人，30天后是2510人 - 30人 = 2480人\n",
      "剩下的食物是根据2510人 / 2480人 = 1余350人\n",
      "所以剩下350天，直到食物耗尽。\n",
      "</reasoning>\n",
      "<answer>\n",
      "350天\n",
      "</answer> \n",
      "提取后的答案:\n",
      "350天\n",
      "问题:\n",
      "阿内尔有十盒铅笔，每盒里的铅笔数量相同。他保留了十支铅笔，并将剩余的铅笔平分给他的五个朋友。如果他的朋友每人有八支铅笔，每个盒子里有多少支铅笔？ \n",
      "答案:\n",
      "5 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "阿内尔共有10盒铅笔，每盒的铅笔数量相同。他保留了10支铅笔，所以还有9支铅笔。将这些9支铅笔平分给他的五个朋友，每个朋友可以获得9支铅笔，所以每个盒子的铅笔数量为9除以5。\n",
      "\n",
      "9 ÷ 5 = 1.8（但是答案应该是整数，应该通过简单的除法计算得出具体的铅笔数量）\n",
      "\n",
      "1.8 / 5 = 1.8 / 5\n",
      "1.8 / 5 = 0.36\n",
      "每个盒子里有0支铅笔。\n",
      "</reasoning>\n",
      "<answer>\n",
      "0\n",
      "</answer> \n",
      "提取后的答案:\n",
      "0\n",
      "问题:\n",
      "亚历克斯用丝绸制作奢华连衣裙。每件衣服需要 5 米丝绸，Alex 拥有 600 米丝绸储备。他的朋友们也想学习如何制作这些衣服，因此 Alex 给了他们 5 个人每人 20 米的丝绸。他用剩下的钱自己制作衣服。亚历克斯可以制作多少件衣服？ \n",
      "答案:\n",
      "100 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "Alex 收集了 500 米的丝绸，给他的 5 个朋友每人 20 米后剩下 500 - 5 * 20 = 350 米\n",
      "每件衣服需要 5 米丝绸，所以 Alex 可以制作的衣物数量为 350 / 5 = 70 件\n",
      "</reasoning>\n",
      "<answer>\n",
      "70\n",
      "</answer>\n",
      " \n",
      "提取后的答案:\n",
      "70\n",
      "问题:\n",
      "汉娜养了三只狗。第一只狗每天吃1.5杯狗粮。第二只狗的食量是第二只狗的两倍，而第三只狗的食量比第二只狗多 2.5 杯。汉娜每天应该为她的三只狗准备多少杯狗粮？ \n",
      "答案:\n",
      "10 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "1. 第一只狗每天吃1.5杯狗粮。\n",
      "2. 第二只狗的食量是第一只狗的两倍，所以第二只狗每天吃 \\(1.5 \\times 2 = 3\\) 杯狗粮。\n",
      "3. 第三只狗的食量比第二只狗多2.5杯，所以第三只狗每天吃 \\(3 + 2.5 = 5.5\\) 杯狗粮。\n",
      "4. 总共每天需要给三只狗准备 \\(1.5 + 3 + 5.5 = 10\\) 杯狗粮。\n",
      "</reasoning>\n",
      "<answer>\n",
      "10\n",
      "</answer> \n",
      "提取后的答案:\n",
      "10\n",
      "问题:\n",
      "在一次学校去海边的旅行中，艾伦和他的朋友们收集了贝壳。艾伦收集的贝壳数量是本收集的四倍。本起步较晚，只收集到了劳里的三分之一。如果劳里收集了 36 个贝壳，艾伦收集了多少个？ \n",
      "答案:\n",
      "48 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "艾伦收集的贝壳数量是本的四倍，但本只收集到了劳里的三分之一，所以艾伦收集了 \\( \\frac{3}{4} \\times 36 = 27 \\) 个贝壳\n",
      "</reasoning>\n",
      "<answer>\n",
      "27\n",
      "</answer> \n",
      "提取后的答案:\n",
      "27\n",
      "问题:\n",
      "音乐会门票票价为 40 美元。 Benson 先生购买了 12 张票，每购买超过 10 张票即可享受 5% 的折扣。Benson 先生总共支付了多少钱？ \n",
      "答案:\n",
      "476 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "因为票价为 40 美元，每超过 10 张票就享受 5% 的折扣，所以票价的 95% 是 36 美元；\n",
      "购买 12 张票可以享受的折扣为：12 - 10 = 2 张票，折扣为：2 * 5% = 0.1 美元；\n",
      "所以实际支付的金额为12 × 36 美元 - 0.1 美元 = 435.9 美元\n",
      "</reasoning>\n",
      "<answer>\n",
      "435.9\n",
      "</answer> \n",
      "提取后的答案:\n",
      "435.9\n",
      "问题:\n",
      "一家服装店出售 20 件衬衫和 10 条牛仔裤。一件衬衫每件 10 美元，一条牛仔裤的价格是每件的两倍。如果所有衬衫和牛仔裤都卖掉，服装店能赚多少钱？ \n",
      "答案:\n",
      "400 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "衬衫价格：20件 × 10美元/件 = 200美元\n",
      "牛仔裤价格：10条 × 2 × 10美元/条 = 200美元\n",
      "服装店总共赚的钱：200美元 + 200美元 = 400美元\n",
      "</reasoning>\n",
      "<answer>\n",
      "400\n",
      "</answer> \n",
      "提取后的答案:\n",
      "400\n",
      "问题:\n",
      "从中午零开始，建筑物的阴影每隔一小时就会额外延伸 5 英尺。中午 6 点后建筑物的影子有多长（以英寸为单位）？ \n",
      "答案:\n",
      "360 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "在这个例子中，我们不需要进行任何计算。阴影每隔一小时就会额外延伸5英寸的影子，所以无论什么时候中午6点后建筑物的影子长度不会改变。因此，阴影的总长度不变是15英寸。\n",
      "</reasoning>\n",
      "<answer>\n",
      "15\n",
      "</answer>\n",
      " \n",
      "提取后的答案:\n",
      "15\n",
      "问题:\n",
      "哈德利到处都穿着他的牛仔靴。他穿着靴子步行 2 英里来到杂货店。然后他穿着靴子走了不到两英里，来到了宠物店。然后，他穿着靴子走了不到四英里回家。哈德利穿着靴子走了多远（以英里为单位）？ \n",
      "答案:\n",
      "6 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "首先，哈德利的牛仔靴让他步行2英里。\n",
      "接着，然后他步行到了宠物店，然后又走了一英里，总共2英里。\n",
      "最后，到了杂货店后，他又走了不到4英里回家。\n",
      "因此，哈德利总共穿着靴子走了2 + 2 + 4 = 8英里。\n",
      "</reasoning>\n",
      "<answer>\n",
      "8\n",
      "</answer> \n",
      "提取后的答案:\n",
      "8\n",
      "问题:\n",
      "游乐园内有84人排队等候乘坐过山车。过山车有7节车厢，每节车厢可坐2人。游乐设施运营商需要运行过山车多少次才能让排队的每个人都转一圈？ \n",
      "答案:\n",
      "6 \n",
      "模型输出:\n",
      "游乐园内排队等待乘坐过山车的人数为84人。每节车厢容量为2人，所以可以容纳的过山车数量为 \\(84 \\div 2 = 42\\) 节。每节过山车转一圈需要2圈（因为过山车有7节车厢，每节车厢每圈内有 \\(2-1=1\\) 圈）。\n",
      "\n",
      "所以，需要运行过山车的次数为 \\(42 \\div 1 = 42\\) 次。\n",
      "\n",
      "游乐设施运营商需要运行过山车42次才能让排队的每个人都转一圈。 \n",
      "提取后的答案:\n",
      "游乐园内排队等待乘坐过山车的人数为84人。每节车厢容量为2人，所以可以容纳的过山车数量为 \\(84 \\div 2 = 42\\) 节。每节过山车转一圈需要2圈（因为过山车有7节车厢，每节车厢每圈内有 \\(2-1=1\\) 圈）。\n",
      "\n",
      "所以，需要运行过山车的次数为 \\(42 \\div 1 = 42\\) 次。\n",
      "\n",
      "游乐设施运营商需要运行过山车42次才能让排队的每个人都转一圈。\n",
      "问题:\n",
      "一块馅饼售价 4 美元。每个馅饼有 3 块。面包店一小时内可以制作 12 个馅饼。面包店制作一个馅饼的成本为 0.5 美元。考虑到面包店能够出售所有的馅饼块，它会赚多少钱？ \n",
      "答案:\n",
      "138 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "对于每个馅饼，面包店的制作成本是0.5美元，所以制作1个馅饼的成本是0.5美元\n",
      "对于每个馅饼有3块，所以制作1个馅饼需要的成本是3 * 0.5美元 = 1.5美元\n",
      "面包店一小时内可以制作12个馅饼，所以制作6个馅饼的成本是6 * 1.5美元 = 9美元\n",
      "给客户每个馅饼是4美元，所以6个馅饼的售价是4美元 * 6个 = 24美元\n",
      "所以，面包店制作一个馅饼的成本是0.5美元，制作6个馅饼的成本是6 * 0.5美元 = 3美元\n",
      "所以，面包店制作一个馅饼的成本为9美元 + 3美元 = 12美元\n",
      "因为面包店制作一个馅饼的成本是12美元，所以面包店每卖出一个 \n",
      "提取后的答案:\n",
      "<reasoning>\n",
      "对于每个馅饼，面包店的制作成本是0.5美元，所以制作1个馅饼的成本是0.5美元\n",
      "对于每个馅饼有3块，所以制作1个馅饼需要的成本是3 * 0.5美元 = 1.5美元\n",
      "面包店一小时内可以制作12个馅饼，所以制作6个馅饼的成本是6 * 1.5美元 = 9美元\n",
      "给客户每个馅饼是4美元，所以6个馅饼的售价是4美元 * 6个 = 24美元\n",
      "所以，面包店制作一个馅饼的成本是0.5美元，制作6个馅饼的成本是6 * 0.5美元 = 3美元\n",
      "所以，面包店制作一个馅饼的成本为9美元 + 3美元 = 12美元\n",
      "因为面包店制作一个馅饼的成本是12美元，所以面包店每卖出一个\n",
      "问题:\n",
      "黎明、莉迪亚和唐娜总共有 200 根香蕉。多恩比莉迪亚多 40 根香蕉。如果莉迪亚有 60 根香蕉，唐娜有多少根香蕉？ \n",
      "答案:\n",
      "40 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "已知唐娜有60根香蕉，又知多恩比莉迪亚多40根香蕉，则说明多恩有60+40=100根香蕉。\n",
      "如果黎明、莉迪亚和唐娜总共有200根香蕉，那么唐娜的香蕉数为200-60-100=60根\n",
      "</reasoning>\n",
      "<answer>\n",
      "60\n",
      "</answer> \n",
      "提取后的答案:\n",
      "60\n",
      "问题:\n",
      "巴兹尔在早上和睡前吃 1/2 块狗饼干。她白天会得到两块完整的饼干。巴兹尔饼干每盒包装有 45 块饼干。她需要多少盒子才能维持 30 天？ \n",
      "答案:\n",
      "2 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "30 天里，巴兹尔每天会吃 1/2 块狗饼干，所以她每天吃 1/2x 45 = 22.5 块饼干。因此，她将需要 30 / 22.5 = 1.33 天去完成一天的饼干。然而，我们应使用整数表示，这意味着她需要一天半的饼干（3天的总饼干数减去需要的0.33天的剩余饼干）。因此她每个月需要1.33天内的饼干数量是30 * 45 * (1/2) = 562.5块，这相当于约88盒。所以，她需要88个盒子。\n",
      "</reasoning>\n",
      "<answer>\n",
      "88\n",
      "</answer>\n",
      " \n",
      "提取后的答案:\n",
      "88\n",
      "问题:\n",
      "马德琳有 5 个盒子，每个盒子里有 24 支蜡笔。她注意到2个盒子里有5/8的蜡笔还没有使用。另外2个盒子里只用了2/3的蜡笔，最后一个盒子还没有完全用完。玛德琳有多少未使用的蜡笔？ \n",
      "答案:\n",
      "70 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "每个盒子里有24支蜡笔，所以5个盒子里有 \\(5 \\times 24 = 120\\) 支蜡笔。\n",
      "\n",
      "第一个盒子里有 \\(\\frac{5}{8}\\) 的未使用蜡笔，也就是 \\(\\frac{5}{8} \\times 120 = 75\\) 支。\n",
      "\n",
      "第二个盒子里有 \\(\\frac{2}{3}\\) 的蜡笔，所以第二个盒子里有 \\(\\frac{2}{3} \\times 120 = 80\\) 支蜡笔。\n",
      "\n",
      "最后一个盒子还没完全用完，所以它有 0 支未使用蜡笔。\n",
      "\n",
      "总未使用的蜡笔数量 = 第一个盒子里未使用的蜡笔数量 + 第二个盒子里未使用的蜡笔数量 + 最后一个盒子未使用的蜡笔数量\n",
      "</reasoning>\n",
      "<answer>\n",
      "\\[75 + 80 + 0 \n",
      "提取后的答案:\n",
      "\\[75 + 80 + 0\n",
      "问题:\n",
      "布伦丹每天可以割 8 码的草，他买了一台割草机，这帮助他每天割草量增加了 50%。一周后布伦丹能剪多少码？ \n",
      "答案:\n",
      "84 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "在购买割草机后，布伦丹的割草机每天可以帮助他割草8 * 1.5 = 12码\n",
      "一周后，布伦丹每天可以割草12 * 7 = 84码\n",
      "</reasoning>\n",
      "<answer>\n",
      "84码\n",
      "</answer> \n",
      "提取后的答案:\n",
      "84码\n",
      "问题:\n",
      "伊蒂曼纳克和金努克是一对生活在阿拉斯加荒野最北部地区的爱斯基摩夫妇。他们和孩子 Oomyapeck 住在一起。伊蒂曼纳克每天都会捕到足够他们三人一天吃的鱼，然后他们将鱼平分给三人。但在他们把鱼劈开后，他们把所有的眼睛都给了奥米亚佩克，奥米亚佩克把其中两个眼睛给了他的狗，剩下的自己吃掉了。如果 Oomyapeck 一天吃 22 只眼睛，每人可以吃多少条鱼？ \n",
      "答案:\n",
      "4 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "伊蒂曼纳克和金努克在捕到鱼之前，将鱼劈开后，把所有的眼睛都给了奥米亚佩克，这说明每个人实际上只吃到了他们的眼睛，所以他们每人只能吃1条鱼\n",
      "</reasoning>\n",
      "<answer>\n",
      "每人可以吃1条鱼\n",
      "</answer> \n",
      "提取后的答案:\n",
      "每人可以吃1条鱼\n",
      "问题:\n",
      "3 头狮子和 2 头犀牛逃离动物园。如果恢复每只动物需要 2 小时，那么动物园花了多长时间恢复动物？ \n",
      "答案:\n",
      "10 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "3 头狮子需要的恢复时间是 3 小时，2 头犀牛需要的恢复时间是 2 小时。所以总共需要的时间是 3 小时 + 2 小时 = 5 小时\n",
      "</reasoning>\n",
      "<answer>\n",
      "5 小时\n",
      "</answer> \n",
      "提取后的答案:\n",
      "5 小时\n",
      "问题:\n",
      "伊万的院子里有一个喂鸟器，里面装有两杯鸟食。每周，他都必须补充空的喂食器。每杯鸟食可以喂十四只鸟，但伊万每周都会不断地赶走一只饥饿的松鼠，它会从喂食器里偷走半杯鸟食。伊万的喂鸟器每周喂多少只鸟？ \n",
      "答案:\n",
      "21 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "每天一只松鼠从伊万的喂鸟器中偷走1/2杯鸟食\n",
      "每周四天，每只松鼠偷走的鸟食为2杯\n",
      "2 + 4 = 6\n",
      "伊万的喂鸟器每周喂六只鸟\n",
      "</reasoning>\n",
      "<answer>\n",
      "6\n",
      "</answer> \n",
      "提取后的答案:\n",
      "6\n",
      "问题:\n",
      "一年前，购买割草机的总成本比现在低 2/5。如果一年前的成本是 1800 美元，请计算卢西安先生购买 4 台这样的割草机需要花费多少钱。 \n",
      "答案:\n",
      "10080 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "假设三年前的成本是 Y 美元。根据题目，一年前的成本是 Y 美元的 2/5，所以 Y=$1800 除以 2/5，即 Y=$9000\n",
      "4台割草机的总成本就是 $9000 \\times 4$，计算过程：$9000 \\times 4=36000$美元\n",
      "</reasoning>  \n",
      "<answer> \n",
      "36000美元\n",
      "</answer> \n",
      "提取后的答案:\n",
      "36000美元\n",
      "问题:\n",
      "一个农民拥有的猪是牛的两倍，牛是山羊的四倍。如果农民总共有 56 只动物，他有多少只山羊？ \n",
      "答案:\n",
      "11 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "设牛的数量为x，则有 4x=2x+56。\n",
      "解这个方程得到x=14，意味着农民有14只牛。\n",
      "接着，我们知道猪的数量为牛的两倍，所以猪的数量为2x，即2*14=28只。\n",
      "所以农民有28只山羊。\n",
      "</reasoning>\n",
      "<answer>\n",
      "28\n",
      "</answer> \n",
      "提取后的答案:\n",
      "28\n",
      "问题:\n",
      "卡拉正在制作冰沙。如果她使用 500 毫升西瓜泥和 100 毫升奶油，她可以制作多少份 150 毫升？ \n",
      "答案:\n",
      "4 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "150 毫升的冰沙总量应该是 500 毫升的西瓜泥加 100 毫升的奶油，即\n",
      "500 + 100 = 600 毫升\n",
      "然后将冰沙总量除以每个冰沙的容量，即 600 / 150 = 4\n",
      "\n",
      "因此，卡拉可以制作 4 份 150 毫升的冰沙。\n",
      "</reasoning>\n",
      "<answer>\n",
      "4\n",
      "</answer> \n",
      "提取后的答案:\n",
      "4\n",
      "问题:\n",
      "周末在马里奥理发店理发的费用要贵 50%。如果马里奥周一为最后一次理发支付了 18 美元，那么前一天他会支付多少钱？ \n",
      "答案:\n",
      "27 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "设在周末前，周一前支付的总金额为x元，周末后支付的总金额为y元。\n",
      "一周内，他花费的总金额为2x+50%，即0.2x+50%x=0.7x。\n",
      "我们知道，在周末他支付的总金额是18元，即0.7x=18，解得x=25。这表示在周末前，他为这周总共支付了25元。\n",
      "所以他为周六支付的金额为25的1/2=12.5元（除以50%），即前一天他为周六支付的金额是12.5元。\n",
      "</reasoning>\n",
      "<answer>\n",
      "12.5\n",
      "</answer> \n",
      "提取后的答案:\n",
      "12.5\n",
      "问题:\n",
      "玛莎需要 4 杯浆果和 2 杯浓奶油才能制作 1 夸脱冰淇淋。她想要制作 1 夸脱草莓冰淇淋和 1 夸脱覆盆子冰淇淋。在农贸市场，2 杯装的草莓售价为每个 3 美元，2 杯装的覆盆子售价为每个 5 美元。 4 杯装的浓奶油售价为 4.00 美元。她制作 1 夸脱每个冰淇淋需要多少钱？ \n",
      "答案:\n",
      "20 \n",
      "模型输出:\n",
      "<reasoning>\n",
      "制作 1 夸脱草莓冰淇淋需要的浆果和浓奶油的总价为 2 杯浆果 * 3 美元/杯 + 2 杯浓奶油 * 4.00 美元/杯 = 14 美元\n",
      "制作 1 夸脱覆盆子冰淇淋需要的浆果和浓奶油的总价为 2 杯浆果 * 3 美元/杯 + 2 杯浓奶油 * 5 美元/杯 = 17 美元\n",
      "因此，4 杯装的草莓所需的钱为 14 美元 / 4 杯 = 3.50 美元\n",
      "4 杯装的覆盆子所需的钱为 17 美元 / 4 杯 = 4.25 美元\n",
      "将这两个结果加起来得到制作 \n",
      "提取后的答案:\n",
      "<reasoning>\n",
      "制作 1 夸脱草莓冰淇淋需要的浆果和浓奶油的总价为 2 杯浆果 * 3 美元/杯 + 2 杯浓奶油 * 4.00 美元/杯 = 14 美元\n",
      "制作 1 夸脱覆盆子冰淇淋需要的浆果和浓奶油的总价为 2 杯浆果 * 3 美元/杯 + 2 杯浓奶油 * 5 美元/杯 = 17 美元\n",
      "因此，4 杯装的草莓所需的钱为 14 美元 / 4 杯 = 3.50 美元\n",
      "4 杯装的覆盆子所需的钱为 17 美元 / 4 杯 = 4.25 美元\n",
      "将这两个结果加起来得到制作\n"
     ]
    }
   ],
   "source": [
    "trainer.train()\n",
    "trainer.save_model(output_dir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "911ea3e5-1b6b-4d6d-a150-c84892f9139b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
